// This is JDefenceTower, a simple tower defence style game
//
// Copyright (C) 2010 Maximilian Junker
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see <http://www.gnu.org/licenses/>.

package junker.defence.model;

public class MapLocation {
	/** x-coordinate of the location */
	private float	x;
	/** y-coordinate of the location */
	private float	y;

	public MapLocation(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	Vector substract(MapLocation l){
		return  new Vector(x-l.x,y-l.y);
	}
	
	MapLocation add(Vector v){
		return new MapLocation(x+v.x,y+v.y);
	}
	
	float distanceTo(MapLocation l){
		return substract(l).getLength();
	}

	public float getX() {
		return x;
	}

	public void setX(float x) {
		assert x>0;
		this.x = x;
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		assert y>0;
		this.y = y;
	}
	
	

	@Override
	public String toString() {
		return "MapLocation [x=" + x + ", y=" + y + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Float.floatToIntBits(x);
		result = prime * result + Float.floatToIntBits(y);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MapLocation other = (MapLocation) obj;
		if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
			return false;
		if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
			return false;
		return true;
	}

}
